/*
 * @Author: ReinerLau lk850593913@gmail.com
 * @Date: 2022-09-14 11:30:09
 * @LastEditors: ReinerLau lk850593913@gmail.com
 * @LastEditTime: 2022-09-14 13:40:15
 * @FilePath: \robot\src\views\patroling\composables\useCarLink.js
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { ref, watch } from "vue";
import { getByCarLink } from "@/api/robot-device.js";

export default (caritem) => {
  // 车辆连接栏位
  const columns1 = [
    {
      title: "设备编号",
      prop: "id",
    },
    {
      title: "外设名称",
      prop: "name",
    },
    {
      title: "外设类型",
      prop: "type",
    },
    {
      title: "外设状态",
      prop: "status",
      formatter: true,
    },
    {
      title: "操作",
      prop: "action",
      formatter: true,
    },
  ];

  // 车辆连接数据
  const list1 = ref([]);
  /**
   * @description: 获取车辆连接数据
   * @return {*}
   */
  async function getCarLink() {
    if (caritem.value === "") return;
    const { data } = await getByCarLink(caritem.value, "patroling");
    list1.value = data || [];
  }
  getCarLink();

  // 切换车辆重新请求
  watch(caritem, getCarLink);

  return {
    columns1,
    list1,
    getCarLink,
  };
};
